package com.kirk.cts.ui.view.panel;

import com.kirk.cts.core.event.CrawlerToolEvent;
import com.kirk.cts.core.loader.LanguageLoader;
import com.kirk.cts.ui.widget.SingleRowTabbedPane;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.swing.*;
import java.awt.*;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;


/**
 * <p> SystemTabPanel.java </p>
 *
 * @version 1.0.0
 * @Author kirkliu
 * @Date 2020-09-01 22:21
 * @Description 系统TabPanel
 */
@Component("systemTabPanel")
public class SystemTabPanel extends JPanel implements IPage {
    private static final long serialVersionUID = 1L;
    private SingleRowTabbedPane tabbedPane;

    @Autowired
    public SystemTabPanel(List<ITabPanel> tabPanelList) {
        setLayout(new BorderLayout());
        tabbedPane = new SingleRowTabbedPane(SingleRowTabbedPane.FOUR_BUTTONS, SwingConstants.LEFT);
        tabbedPane.setTabPlacement(JTabbedPane.BOTTOM);
        // 排序
        Collections.sort(tabPanelList, new Comparator<ITabPanel>() {
            public int compare(ITabPanel tabl, ITabPanel tab2) {
                return tabl.getTabPanelIndex() == tab2.getTabPanelIndex() ? 0 : (tabl.getTabPanelIndex() > tab2.getTabPanelIndex() ? 1 : -1);
            }
        });
        for (ITabPanel panel : tabPanelList) {
            tabbedPane.addTab(panel.getTanPanelName(), panel.getPanel());
            panel.init();
        }
        tabbedPane.setSelectedIndex(0);
        add(tabbedPane, BorderLayout.CENTER);
    }

    public SingleRowTabbedPane getTabbedPane() {
        return tabbedPane;
    }

    @Override
    public void update(CrawlerToolEvent event) {

    }

    @Override
    public String getPageId() {
        return this.getClass().getName();
    }

    @Override
    public String getPageName() {
        return LanguageLoader.getString("Home.systemWelcome");
    }

    @Override
    public void disposePage() {
        // TODO Auto-generated method stub
    }

    @Override
    public boolean isDefaultPage() {
        return true;
    }

    @Override
    public void setDefaultPage(boolean bool) {
        // TODO Auto-generated method stub

    }

    @Override
    public void showData(int pageNumber, int pageSize) {
        // TODO Auto-generated method stub

    }

    @Override
    public void init() {
        // TODO Auto-generated method stub

    }

}
